#ifndef _GLOG_H_
#define _GLOG_H_

using namespace std ;

#include <iostream>
#include <fstream>
#include <assert.h>
#include <time.h>

/**
 *
 * @author me
 *
 */
class GLog {

    private:
        // Variables
        ofstream m_stream;
        string filename ;

    public:
        GLog():filename("log/log_"){
            time_t rawtime;
            struct tm * timeinfo;

            time ( &rawtime );
            timeinfo = localtime ( &rawtime );
            filename += asctime (timeinfo) ;

            // Problem with the last character
            filename.resize(filename.size()-1) ;
            for (uint i=0;i<filename.size();++i) {
                if (filename[i]==' ') filename[i] = '_' ;
                if (filename[i]==':') filename[i] = '.' ;
            }
        }

        GLog& operator<<(const string& s) {
            m_stream.open(filename.c_str(),ios_base::app|ios_base::out) ;
            m_stream << s ; m_stream.close() ; return *this ; }
        GLog& operator<<(const int i) {
            m_stream.open(filename.c_str(),ios_base::app|ios_base::out) ;
            m_stream << i ; m_stream.close() ; return *this ; }
        GLog& operator<<(const char c) {
            m_stream.open(filename.c_str(),ios_base::app|ios_base::out) ;
            m_stream << c ; m_stream.close() ; return *this ; }
        GLog& operator<<(const double d) {
            m_stream.open(filename.c_str(),ios_base::app|ios_base::out) ;
            m_stream << d ; m_stream.close() ; return *this ; }
        GLog& operator<<(ostream& os) {
            m_stream.open(filename.c_str(),ios_base::app|ios_base::out) ;
            m_stream << os ; m_stream.close() ; return *this ; }

        // inline
        GLog& operator<<(char* s) { return *this << string(s) ; }
} ;
#endif
